﻿//-----------------------------------------------------------------------
// <copyright file="ProxiedWebRequest.cs" company="WorldView Solutions Inc">
//     Copyright (c) WorldView Solutions Inc. This source is subject to the Microsoft Public License (Ms-PL). All other rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System.Net;

namespace WorldViewSolutions.ArcGISServer.SOE.DataSources
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks></remarks>
	public static class ProxiedWebRequest
	{
        /// <summary>
        /// Creates the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static System.Net.HttpWebRequest Create(string url)
        {
            //TODO: read poxy information from a config file
            return Create(url, null, -1, false);
        }

        /// <summary>
        /// Creates the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="host">The host.</param>
        /// <param name="port">The port.</param>
        /// <param name="bypassProxyOnLocal">if set to <c>true</c> [bypass proxy on local].</param>
        /// <returns></returns>
        /// <remarks></remarks>
		public static System.Net.HttpWebRequest Create(string url, string host, int port, bool bypassProxyOnLocal)
		{
			System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);

            // Setup a WebProxy if needed
			if (host != null && port > -1)
            {
				WebProxy webProxy = new WebProxy(host, port);
                webProxy.BypassProxyOnLocal = bypassProxyOnLocal;
                request.Proxy = webProxy;
            }

			return request;
		}
	}
}